package selenium;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Set;

import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class test8 {
//自动登录测试
	public static void main(String[] args) throws Exception {
		Runtime.getRuntime().exec("taskkill /F /IM chrome.exe");
		Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe");
		String chromedriverExist = "D:/java/chromedriver.exe";
		File chromedriverFileExist = new File(chromedriverExist);// 读driver
		if (!chromedriverFileExist.exists()) {
			chromedriverExist = "D:/java/chromedriver_win32/chromedriver.exe";
		}
		System.getProperties().setProperty("webdriver.chrome.driver", chromedriverExist);
		final WebDriver driver = new ChromeDriver();
		try {
			//driver.manage().window().maximize();
			driver.manage().deleteAllCookies();
			driver.get("http://mp.163.com/wemedia/baseinfo/isexist/5");
			driver.manage().deleteAllCookies();
			SimpleDateFormat sdf = new SimpleDateFormat("M/dd/yyyy hh:mm:ss a",Locale.US);
			
			String name = "NTES_SESS";
			String value = "7jW_ZTAALBB6GCJ_y3T4jl_C_bl4eQVcp6d2BlLRRK65Z2qhZLps8NgbRs6qyu2z4NYogIQXBtf1ZE82SLDipGK0L8gphVLAHn3Eyhqpd6xOef85_6x_9CMwoUKNWOK1EUn6xC6oO7s7thna0jKObI6upxwysXMmU8.SOLiMBoYyK08HaaYawPLFUquV_IBGlJQKPS7h6NLON";
			String domain = ".mp.163.com";
			String path = "/";
			Date expiry = sdf.parse("5/13/2103 10:31:37 AM");
			Cookie cookie = new Cookie(name, value, domain, path, expiry);
			
			driver.manage().addCookie(cookie);
			driver.get("http://mp.163.com/index.html");
			System.out.println("成功登陆 ");
			Set<Cookie> cookies = driver.manage().getCookies();
			System.out.println("打印cookie");
			for (Cookie cookie2 : cookies) {
				System.out.println(cookie2);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		 /*driver.quit();*/
	}

}
